﻿package code {
	
	public class SpinGon extends BaseShape {
		private var armLength:Number;
		public function SpinGon(radius:Number, sides:Number, color:uint, thickness:Number, hollow:Boolean, angle:Number, armLength:Number) {
			super(radius, sides, color, thickness, hollow, angle);
			this.armLength = armLength;
			
			init();
		}
		
		private function init(){
			makeVertices();
			rotateVertices();
			renderVertices();
		}
		
		override public function makeVertices():void{
			var centerX = 0;
			var centerY = 0
			
			// complete me by filling in vertices array with polygon vertices that you calculate procedurally
			var theta = (2 * Math.PI) / sides;  // gets the base value of theta
			
			for(var i:int  = 0; i < sides; i++)  // number of vertices is equal to the number of sides
			{
				var xPos:Number = (radius * Math.cos(i * theta)) + centerX;  // gets the position around the radius each vertex will be and translates it by the center position
				var yPos:Number = (radius * Math.sin(i * theta)) + centerY;
				
				var tempVert:Vertex = new Vertex(xPos, yPos);  // sets up a tempVertex to add to the vertices array
				vertices.push(tempVert);
			}
		}
		
		override public function renderVertices():void{
			// set fill and hollowness:
			graphics.beginFill(color,alpha=(hollow?0:1));
			
			// set border:
			graphics.lineStyle(thickness,color,alpha=1);
			
			// start at this vertex (x=radius,y=0 from center)
			graphics.lineTo(Vertex(vertices[0]).x, Vertex(vertices[0]).y);
			graphics.moveTo(0,0);
			// draw line to each vertex going clockwise from starting vertex:
			for(var side:uint=1; side < sides; side++) {
				graphics.lineTo(Vertex(vertices[side]).x, Vertex(vertices[side]).y);
				graphics.moveTo(0, 0);
			}
			
			// connect the last vertex to starting vertex:
			//graphics.lineTo(Vertex(vertices[0]).x, Vertex(vertices[0]).y);
			
			// done:
			graphics.endFill();
		}

	}
	
}
